--
--SELECT     dbo.Apply.*, dbo.SubsidyRecord.adj_id, dbo.SubsidyRecord.adj_longid, dbo.SubsidyRecord.adj_checked, dbo.SubsidyRecord.adj_reason, 
--                      dbo.SubsidyRecord.adj_noid, dbo.SubsidyRecord.adj_date, dbo.SubsidyRecord.adj_remark, dbo.SubsidyRecord.adj_stoptime, 
--                      dbo.SubsidyRecord.adj_starttime, dbo.SubsidyRecord.adj_iscontinue, dbo.SubsidyRecord.adj_nowarea, 
--
--dbo.SubsidyRecord.adj_moneychange, 
--                      dbo.SubsidyRecord.adj_nowmoney
--FROM         dbo.Apply INNER JOIN
--                      dbo.SubsidyRecord ON dbo.Apply.apply_id = dbo.SubsidyRecord.applyid
--
--where apply_longid='224' and apply.[EffectDate]=200901
--
--
--select * from SubsidyRecord where   cast(Effectdate as varchar(10))+ cast(adj_noid as varchar(10)) =20090120090784
--
--select  cast(Effectdate as varchar(10))+ cast(adj_noid as varchar(10))   from SubsidyRecord
-- group by  cast(Effectdate as varchar(10))+ cast(adj_noid as varchar(10))
--
-- having count(1)>1
----have repeater 6876
----no repeater 6867
----6960
----
--select * into #SubsidyRecord  from SubsidyRecord  
--delete from #SubsidyRecord where adj_id not in 
--(select max(adj_id) from #SubsidyRecord  group by  cast(Effectdate as varchar(10))+ cast(adj_noid as varchar(10)) )
--

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].SubsidyRecord_NoRepeat') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].SubsidyRecord_NoRepeat
go
Create proc  SubsidyRecord_NoRepeat
as 
begin 
delete from SubsidyRecord where adj_id not in 
(select max(adj_id) from SubsidyRecord  group by  cast(Effectdate as varchar(10))+ cast(adj_noid as varchar(10)) )
end 

exec SubsidyRecord_NoRepeat